package beanstao.util.type.base;

import java.lang.reflect.Array;

import beanstao.util.exception.technical.util.reflect.FailToCastObjectException;
import beanstao.util.type.Castor;
import beanstao.util.type.Castors;

public class Array2Object extends Castor<Object, Object>
{

	public Array2Object()
	{
		this.fromClass = Array.class;
		this.toClass = Object.class;
	}

	@Override
	public Object cast(Object src, Class<?> toType, String... args) throws FailToCastObjectException
	{
		if (Array.getLength(src) == 0)
		{
			return null;
		}
		return Castors.me().castTo(Array.get(src, 0), toType);
	}

}
